// 1、数组搜索--before
const fruits=[
    {name:"苹果",order:1},
    {name:"栗子",order:4},
    {name:"香蕉",order:3},
]
function getApples(arr,value){
    for(let index=0;index<arr.length;index++){
        if(arr[index].name===value){
            return arr[index];
        }
    }
}
const result=getApples(fruits,'苹果');
console.log(result);

// 数组搜索--after
function getApples1(arr,value){
    return arr.find((obj)=>obj.name===value)
}
const result1=getApples1(fruits,'栗子');
console.log(result1);

// 2、对象合并--before
const emplogee={name:'张三',age:30};
const salary={grade:'A'}
const summary=salary;
for(const key in emplogee){
    summary[key]=emplogee[key];
}
console.log(summary);
//对象合并--after
const summary1={...emplogee,...salary};
console.log(summary1);


// 3、数组合并--before
const apples=["红苹果","绿苹果"]
const all=["西瓜","草莓"].concat(apples);
console.log(all);
// 数组合并--after
const all1=["西瓜","草莓",...apples];
console.log(all1);


//4、 数组遍历
const cats=["猫","狗","狐狸","老虎"]
for(let i=0;i<cats.length;i++){
    console.log(cats[i]);
}
//for...in返回数组下标
//for...of返回数组对象
for(cat in cats){
    console.log(cat);
}
for(cat of cats){
    console.log(cat);
}



